/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-06-10
 * Time: 21:18
 */
public class test2 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if(headA==null || headB==null){
            return null;
        }
        ListNode cur1 = headA;
        ListNode cur2 = headB;
        while(cur1!=cur2){
            cur1 = cur1==null?headB:cur1.next;
            cur2 = cur2==null?headA:cur2.next;
        }
        return cur1;
    }


     public class ListNode{
        int val;
        ListNode next;

        ListNode(int x){
            val = x;
            next = null;
        }



        ListNode(int val, ListNode next){
            this.val = val;
        }

    }
}
